package com.aken.imdemo.view;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.aken.imdemo.model.EmotionData;
import com.aken.imdemo.model.EmotionItem;
import com.bumptech.glide.Glide;

import java.util.List;

public class GridViewAdapter extends BaseAdapter {

    private List<EmotionItem> mNote = EmotionData.getNotes();

    private Context mContext;

    public GridViewAdapter(Context context) {
        mContext = context;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if (!(view instanceof ImageView)) {
            view = new ImageView(mContext);
        }
        ImageView imageView = (ImageView) view;

        Glide.with(mContext)
                .asGif()
                .load(((EmotionItem) getItem(position)).getIconRes())
                .override(70, 70)
                .into(imageView);

        return view;
    }

    @Override
    public int getCount() {
        return mNote.size();
    }

    @Override
    public Object getItem(int position) {
        return mNote.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}